﻿using GN.Pay.TradeChannel.Configure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel
{
    /// <summary>
    /// 交易通道,实现第三方的交易通道
    /// </summary>
    public interface ITradeChannel : IChannel
    {
        /// <summary>
        /// 获取付款是否每次都是新请求
        /// </summary>
        bool IsPayNewRequest { get; }

        /// <summary>
        /// 通道提供者
        /// </summary>
        string ChannelProvider { get; }

        /// <summary>
        /// 获取通道类型
        /// </summary>
        ChannelType ChannelType { get; }

        /// <summary>
        /// 支付通知响应
        /// </summary>
        /// <param name="isSuccess"></param>
        /// <returns></returns>
        string PayNotifyResponse(bool isSuccess);

        /// <summary>
        /// 退款通知响应
        /// </summary>
        /// <param name="isSuccess"></param>
        /// <returns></returns>
        string RefundNotifyResponse(bool isSuccess);

        /// <summary>
        /// 获取通道配置
        /// </summary>
        ITradeChannelConfigure ChannelConfigure { get; }

        /// <summary>
        /// 读取配置产生的事件
        /// </summary>
       // event EventHandler ReadConfigure;

        /// <summary>
        /// 
        /// </summary>
        Type TradeChannelConfigureInfoType { get; }

        //  /// <summary>
        //  /// 获取转账通知Url
        //  /// </summary>
        ////  string MoveNotifyUrl { get; }

        /// <summary>
        /// 付款申请
        /// </summary>
        /// <param name="order">订单</param>
        /// <returns></returns>
        ITradePayApplyResult PayApply(IOrderPayApply order);

        /// <summary>
        /// 异步付款申请
        /// </summary>
        /// <param name="order">订单</param>
        /// <returns></returns>
        Task<ITradePayApplyResult> PayApplyAsync(IOrderPayApply order);

        /// <summary>
        /// 退款申请
        /// </summary>
        /// <param name="apply"></param>
        /// <returns></returns>
        ITradeRefundApplyResult RefundApply(IRefundApplyInfo apply);

        /// <summary>
        /// 异步退款申请
        /// </summary>
        /// <param name="apply"></param>
        /// <returns></returns>
        Task<ITradeRefundApplyResult> RefundApplyAsync(IRefundApplyInfo apply);

        /// <summary>
        /// 订单单条查询
        /// </summary>
        /// <param name="queryDate">查询日期</param>
        /// <param name="orderNo">订单号</param>
        /// <param name="tradeNo">交易号</param>
        /// <returns></returns>
        ITradeOrderQueryResult OrderSingleQuery(DateTime queryDate, string orderNo, string tradeNo);

        /// <summary>
        /// 订单单笔查询是否可靠
        /// </summary>
        bool OrderSingleQueryIsReliable { get; }

        /// <summary>
        /// 异步订单单条查询
        /// </summary>
        /// <param name="queryDate">查询日期</param>
        /// <param name="orderNo">订单号</param>
        /// <param name="tradeNo">交易号</param>
        /// <returns></returns>
        Task<ITradeOrderQueryResult> OrderSingleQueryAsync(DateTime queryDate, string orderNo, string tradeNo);

        /// <summary>
        /// 订单付款通知
        /// </summary>
        /// <typeparam name="TMessage">消息</typeparam>
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        void OrderPayNotify(INotifyService sercice, object message);

        /// <summary>
        /// 异步订单付款通知
        /// </summary>
        /// <typeparam name="TMessage">消息</typeparam>
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        Task OrderPayNotifyAsync(INotifyService sercice, object message);

        /// <summary>
        /// 订单退款通知
        /// </summary>
        /// <typeparam name="TMessage">消息</typeparam>
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        void OrderRefundNotify(INotifyService sercice, object message);

        /// <summary>
        /// 异步订单退款通知
        /// </summary>
        /// <typeparam name="TMessage">消息</typeparam>
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        Task OrderRefundNotifyAsync(INotifyService sercice, object message);
    }

    /// <summary>
    /// 具有泛型通知的交易通道
    /// </summary>
    /// <typeparam name="TNotify"></typeparam>
    public interface ITradeChannel<TNotify> : ITradeChannel where TNotify : class
    {
        /// <summary>
        /// 订单付款通知
        /// </summary>      
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        void OrderPayNotify(INotifyService sercice, TNotify message);

        /// <summary>
        /// 异步订单付款通知
        /// </summary>      
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        Task OrderPayNotifyAsync(INotifyService sercice, TNotify message);

        /// <summary>
        /// 订单退款通知
        /// </summary>     
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        void OrderRefundNotify(INotifyService sercice, TNotify message);

        /// <summary>
        /// 异步订单退款通知
        /// </summary>     
        /// <param name="sercice">服务</param>
        /// <param name="message">消息</param>
        Task OrderRefundNotifyAsync(INotifyService sercice, TNotify message);
    }
}
